<%
/*
Copyright 2010-2011 CumulusCloud
http://cumuluscloud.cc

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

%>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<%@page import="cumulusCloud.common.HtmlComponents"%>

<%@page import="cumulusCloud.common.objects.CloudConfiguration"%>
<%@page import="cumulusCloud.common.ManageConfiguration"%><html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
<%=HtmlComponents.headBannerCSS(true)%>
<%=HtmlComponents.headApplicationIcon("configuration", true)%>
<title>Cloud - Configuration</title>


</head>
<body>
<%=HtmlComponents.bodyTopBanner("Configuration", true, true)%>

<%
String action = request.getParameter("action");
if ("save".equals(action)) {
	CloudConfiguration newConfig = ManageConfiguration.getPendingConfig();
	try {
		int port = Integer.parseInt(request.getParameter("httpport"));
		newConfig.httpPort = port;
	} catch (Exception e) {
		out.println("<p style=\"color: red\">The HTTP port is not a valid number</p>");
	}
	
	try {
		int port = Integer.parseInt(request.getParameter("httpsport"));
		newConfig.httpsPort = port;
	} catch (Exception e) {
		out.println("<p style=\"color: red\">The HTTPS port is not a valid number</p>");
	}
	
	ManageConfiguration.setNewConfig(newConfig);
	
	out.println("<hr />");
}
%>

<%
CloudConfiguration currentConfig = ManageConfiguration.getCurrentConfig();
CloudConfiguration pendingConfig = ManageConfiguration.getPendingConfig();

if (!currentConfig.equals(pendingConfig)) {
	out.println("<p style=\"color: orange\">There are pending changes. You must restart the Cloud to make them effectives.</p>");
}
%>

<p>Current Config</p>
<table border="1">
<tr><td>HTTP port</td><td><%=currentConfig.httpPort %></td></tr>
<tr><td>HTTPS port</td><td><%=currentConfig.httpsPort %></td></tr>
</table>

<p>Configure</p>
<form action="." method="post">
<table border="1">
<tr><td>HTTP port (default 80) (-1 to disable)</td><td><input name="httpport" type="text" value="<%=pendingConfig.httpPort %>"/></td></tr>
<tr><td>HTTPS port (default 443) (-1 to disable)</td><td><input name="httpsport" type="text" value="<%=pendingConfig.httpsPort %>"/></td></tr>
</table>
<p><input name="action" type="hidden" value="save"/>
<input type="submit" value="Save"/></p>
</form>

</body>
</html>